package com.aps.common.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author nbZhuozh
 * @Date 2025-09-08  17:07
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OperationAbandoned {

    @Schema(description = "工序ID", example = "OP001")
    private String operationId;

    @Schema(description = "工序名称", example = "车削")
    private String operationName;

    @Schema(description = "工序序号", example = "1")
    private Integer sequence;

    @Schema(description = "可用设备数据")
    private List<EquipmentAbandoned> equipment;

    @Schema(description = "订单数据id")
    private String orderId;

    @Schema(description = "计划开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime plannedStartTime;

    @Schema(description = "计划完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime plannedEndTime;

    @Schema(description = "分配的设备ID", example = "EQ001")
    private String assignedEquipmentId;

    @Schema(description = "分配的人员ID", example = "PER001")
    private String assignedPersonnelId;

    @Schema(description = "标准工时(分钟)", example = "30.0")
    private Double standardTime;

    @Schema(description = "换型时间(分钟)", example = "15.0")
    private Double setupTime;

//    @Schema(description = "人员要求", example = "中级车工")
//    private String personnelRequirement;
//
//    @Schema(description = "质量要求", example = "表面粗糙度Ra1.6")
//    private String qualityRequirement;

    /**
     * 构造函数
     *
     * @param id 工序ID
     * @param order 所属订单
     * @param machine 执行设备
     * @param unitProcessingTime 单位加工时间（分钟/个）
     * @param sequence 工序顺序号
     */
    public OperationAbandoned(String id, String orderId, List<EquipmentAbandoned> machine, double unitProcessingTime, int sequence) {
        if (id == null || id.trim().isEmpty()) {
            throw new IllegalArgumentException("工序ID不能为空");
        }
        if (orderId == null) {
            throw new IllegalArgumentException("所属订单不能为空");
        }
//        if (machine == null) {
//            throw new IllegalArgumentException("执行设备不能为空");
//        }
        if (unitProcessingTime <= 0) {
            throw new IllegalArgumentException("单位加工时间必须大于0");
        }
        if (sequence <= 0) {
            throw new IllegalArgumentException("工序顺序号必须大于0");
        }

        this.operationId = id;
        this.orderId = orderId;
        this.equipment = machine;
        this.standardTime = unitProcessingTime;
        this.sequence = sequence;
    }





}
